import request from './request';
import Taro from '@tarojs/taro';
import { BASE_URL } from './request';
// 修改导入方式，FormData是默认导出
import FormData from '../utils/formData/formData';
// 添加 token
const token = Taro.getStorageSync('token');

export const chatApi = {
  getHistory: (assigneeId) => {
    return request.get(`/gpt/conversation/${assigneeId}/limited_messages`);
  },
  sendMessage: (message, sessionId) => {
    let formData = new FormData();
    formData.append('content', message);
    const data = formData.getData();
    return wx.request({
      url: `${BASE_URL}/gpt/chat`,
      enableChunked: true,
      method: 'POST',
      header: {
        'Session-Id': sessionId,
        'Content-Type': data.contentType,
        'Authorization': `Bearer ${token}`
      },
      data: data.buffer
    });
  }
};
